package com.dingreading.cloud.ssxcx.controller;

import com.dingreading.cloud.common.base.R;
import com.dingreading.cloud.common.util.aliyun.MstCdnUtil;
import com.dingreading.cloud.ssxcx.service.XcxAttendClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/xcx/attendClass")
@Api(tags = "小程序-学生学习课程管理")
public class XcxAttendClassController {
    @Resource
    private XcxAttendClassService xcxAttendClassService;

    @ApiOperation(value = "获取当前学生参与的课程")
    @PostMapping(value = "/getMainSubject", produces = "application/json; charset=UTF-8")
    public R<Object> getMainSubject(
            @ApiParam(value = "伙伴uid") @RequestParam(value = "agencyUid") String agencyUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "学生studentUid") @RequestParam(value = "studentUid") String studentUid
    ) {
        R<Object> ret = xcxAttendClassService.getMainSubject(agencyUid, storeUid, studentUid);
        return ret;
    }
    @ApiOperation(value = "获取当前学生课程下的目录")
    @PostMapping(value = "/getSubjectTree", produces = "application/json; charset=UTF-8")
    public R<Object> getSubjectTree(
            @ApiParam(value = "伙伴uid") @RequestParam(value = "agencyUid") String agencyUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "学生studentUid") @RequestParam(value = "studentUid") String studentUid,
            @ApiParam(value = "主课程Uid") @RequestParam(value = "subjectUid") String subjectUid
    ) {
        R<Object> ret = xcxAttendClassService.getSubjectTree(agencyUid, storeUid, studentUid, subjectUid);
        return ret;
    }

    @ApiOperation(value = "获取当前学生目录结构")
    @PostMapping(value = "/getAllSubjectTree", produces = "application/json; charset=UTF-8")
    public R<Object> getAllSubjectTree(
            @ApiParam(value = "伙伴uid") @RequestParam(value = "agencyUid") String agencyUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "学生studentUid") @RequestParam(value = "studentUid") String studentUid
    ) {
        R<Object> ret = xcxAttendClassService.getAllSubjectTree(agencyUid, storeUid, studentUid);
        return ret;
    }

    @ApiOperation(value = "根据最后一层阶段uid获取对应的课节数量")
    @PostMapping(value = "/getSubjectLessonNum", produces = "application/json; charset=UTF-8")
    public R<Object> getSubjectLessonNum(
            @ApiParam(value = "伙伴uid") @RequestParam(value = "agencyUid") String agencyUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "阶段subjectUid") @RequestParam(value = "subjectUid") String subjectUid
    ) {
        R<Object> ret = xcxAttendClassService.getSubjectLessonNum(agencyUid, storeUid, subjectUid);
        return ret;
    }

    @ApiOperation(value = "获取当前课节的课前/中/后信息")
    @PostMapping(value = "/getBean", produces = "application/json; charset=UTF-8")
    public R<Object> getBean(
            HttpServletRequest request,
            @ApiParam(value = "伙伴uid") @RequestParam(value = "agencyUid") String agencyUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "课节uid") @RequestParam(value = "subjectLessonUid") String subjectLessonUid,
            @ApiParam(value = "课节阶段: 1-课前, 2-课中, 3-课后, 4-名师精讲") @RequestParam(value = "materialStage") Integer materialStage
    ) {
        R<Object> r = MstCdnUtil.getIp(request);
        if (R.isError(r))
            return r;
        String ip = (String) r.getData();

        return xcxAttendClassService.getBean(agencyUid, storeUid, subjectLessonUid, materialStage, ip);
    }

    @ApiOperation(value = "记录学生的学习轨迹")
    @PostMapping(value = "/setLearnRecord", produces = "application/json; charset=UTF-8")
    public R<Object> setLearnRecord(
            @ApiParam(value = "伙伴uid") @RequestParam(value = "agencyUid") String agencyUid,
            @ApiParam(value = "门店uid") @RequestParam(value = "storeUid") String storeUid,
            @ApiParam(value = "学生studentUid") @RequestParam(value = "studentUid") String studentUid,
            @ApiParam(value = "课节uid") @RequestParam(value = "subjectLessonUid") String subjectLessonUid,
            @ApiParam(value = "课节阶段: 1-课前, 2-课中, 3-课后, 4-名师精讲") @RequestParam(value = "materialStage") Integer materialStage
    ) {
        return xcxAttendClassService.setLearnRecord(agencyUid, storeUid, studentUid, subjectLessonUid, materialStage);
    }

}
